import React, { Component } from 'react';
import './index.css';
import PubSub from 'pubsub-js';

export default class UserList extends Component {
  state = {
    userList: [],
    loading: false,
    isFirst: true,
    error: ''
  };
  componentDidMount() {
    PubSub.subscribe('getUserList', (_, data) => {
      console.log('订阅数据', data);
      this.setState({
        userList: data
      });
    });
  }

  render() {
    return (
      <div className="row">
        {this.state.userList.map((item) => {
          return (
            <div className="card" key={item.id}>
              <a href={item.html_url} rel="noreferrer" target="_blank">
                <img alt='hehe' src={item.avatar_url} style={{ width: '100px' }} />
              </a>
              <p className="card-text">{item.login}</p>
            </div>
          );
        })}
      </div>
    );
  }
}
